package com.corpgovernment.organization.service;

import java.util.List;

import java.util.List;

import com.corpgovernment.api.organization.bo.FindManageFuzzyRequestBO;
import com.corpgovernment.api.organization.bo.SearchEmployeeInfoRequestBO;
import com.corpgovernment.api.organization.bo.UpdateEmployeeRequestBO;
import com.corpgovernment.api.organization.bo.UpdateEmployeeResponseBO;
import com.corpgovernment.api.organization.model.settlement.QueryEmployeeInfoWithPermissionRequest;
import com.corpgovernment.api.organization.model.settlement.QueryEmployeeInfoWithPermissionResponse;
import com.corpgovernment.api.organization.dto.EmployeeInfoVo;
import com.corpgovernment.api.organization.dto.request.EmployeeByUidRequestVo;
import com.corpgovernment.api.organization.model.employee.ListEmployeeByConditionRequest;
import com.corpgovernment.api.organization.model.employee.ListEmployeeByConditionResponse;
import com.corpgovernment.api.organization.model.org.queryEmployee.QueryEmployeeRequest;
import com.corpgovernment.api.organization.model.org.queryEmployee.QueryEmployeeResponse;
import com.corpgovernment.api.organization.model.user.employee.EmployeeInfoResponseBo;
import com.corpgovernment.api.organization.model.user.employee.EmployeeOrgVo;
import com.corpgovernment.api.organization.model.user.employee.OrgEmployeeVo;
import com.corpgovernment.api.organization.model.user.employee.OrgPostLogVo;
import com.corpgovernment.api.organization.model.user.employee.front.SubmitSelectEmpVo;
import com.corpgovernment.common.base.Page;
import com.corpgovernment.organization.dto.OrgUserInfoPk;
import com.corpgovernment.organization.dto.UserEmailDTO;
import com.corpgovernment.organization.entity.db.MbOrgEmployeeInfo;
import com.corpgovernment.organization.entity.db.MbOrgUserFfpinfo;
import com.corpgovernment.organization.entity.db.MbOrgUserIdcard;
import com.corpgovernment.organization.entity.db.MbUserOrgRelation;
import com.corpgovernment.organization.enumm.ServiceErrorEnum;
import com.corpgovernment.organization.vo.SearchCorpEmpResponse;
import com.ctrip.corp.obt.shard.sql.mybatis.interceptor.pagination.IPage;
/**
 * 员工用户信息service接口
 *
 * @author wangyujue
 */
public interface IOrganizationEmployeeService {

    /**
     * 添加员工
     *
     * @param mbOrgEmployeeInfo
     * @return
     */
    boolean create(MbOrgEmployeeInfo mbOrgEmployeeInfo);

    /**
     * 更新员工
     *
     * @param mbOrgEmployeeInfo
     * @return
     */
    boolean update(MbOrgEmployeeInfo mbOrgEmployeeInfo);

    /**
     * 全量更新员工
     *
     * @param mbOrgEmployeeInfo
     * @return
     */
    boolean updateAll(MbOrgEmployeeInfo mbOrgEmployeeInfo);

    /**
     * 删除员工
     *
     * @param uid
     * @return
     */
    boolean deleteByUid(String uid);

//    /**
//     * 通过组织结构ids查询员工用户列表
//     *
//     * @param orgIds   组织结构ids
//     * @param pageNum
//     * @param pageSize
//     * @return 员工列表
//     */
//    List<MbOrgEmployeeInfo> batchFindAllByOrgIds(List<String> orgIds, Integer pageNum, Integer pageSize);
//
//    /**
//     * 通过组织结构ids查询后台员工用户列表
//     *
//     * @param orgIds   组织结构ids
//     * @param pageNum
//     * @param pageSize
//     * @return 员工列表
//     */
//    List<MbOrgEmployeeInfo> batchFindAllBackgroundByOrgIds(List<String> orgIds, Integer pageNum, Integer pageSize);

//    /**
//     * 通过组织结构ids查询员工用户列表
//     *
//     * @param orgIds   组织结构ids
//     * @param name     用户名关键字
//     * @param pageNum
//     * @param pageSize
//     * @return 员工列表
//     */
//    List<MbOrgEmployeeInfo> listPageByOrgIdsAndName(List<String> orgIds, String name, Integer pageNum, Integer pageSize);

    /**
     * 通过uid查询员工用户信息
     *
     * @param uid 用户id
     * @return 员工信息
     */
    MbOrgEmployeeInfo findByUid(String uid);

    /**
     * 通过uid查询用户，不区分前后台
     *
     * @param uid 用户id
     * @return 员工信息
     */
    MbOrgEmployeeInfo findAllByUid(String uid);

//    /**
//     * 模糊搜索员工
//     *
//     * @param request
//     * @return
//     */
//    List<SearchEmployeeInfo> searchEmployeeInfoList(SearchEmployeeInfoRequest request);

    /**
     * 通过岗位id查找员工列表
     *
     * @param postId   岗位id
     * @param pageNum  起始页
     * @param pageSize 每页条数
     * @return 员工列表 uid,name,orgId,orgName,role,roleName,valid
     */
    List<MbOrgEmployeeInfo> listPageByPostId(Long postId, Integer pageNum, Integer pageSize);

    /**
     * 查询部门下所有员工
     *
     * @param departmentId 部门id
     * @param name         用户名模糊匹配
     * @return 员工列表
     */
    List<MbOrgEmployeeInfo> listAllByDepartmentIdAndName(String departmentId, String name);

//    /**
//     * 清空岗位下所有员工
//     *
//     * @param postId 岗位id
//     * @return 是否成功
//     */
//    boolean clearPostEmployeeByPostId(Long postId);

    /**
     * 前端批量更新用户的岗位接口
     *
     * @param uidList
     * @param postId
     * @param orgId
     * @return
     */
    boolean frontBatchUpdateEmployeePost(List<String> uidList, Long postId, String orgId);

    /**
     * 通过用户名模糊匹配查询
     *
     * @param name 用户姓名
     * @return
     */
    List<MbOrgEmployeeInfo> listByName(String name);

    List<MbOrgEmployeeInfo> listByNameAllPlat(String name);

    /**
     * 通过岗位查找用户
     *
     * @param postId
     * @return
     */
    List<MbOrgEmployeeInfo> listByPostId(Long postId);


	/**
	 * 	通过岗位或uid查询用户(分页)
	 * @param postId
	 * @param pageNum
	 * @param pageSize
	 * @param uid
	 * @return
	 */
	List<MbOrgEmployeeInfo> listPageByPostIdOrUid(Long postId, Integer pageNum, Integer pageSize, String uid,List<String> orgIds);

	/**
	 * 	通过岗位或uid查询用户
	 * @param postId
	 * @param uid
	 * @return
	 */
	List<MbOrgEmployeeInfo> listByPostIdOrUid(Long postId, String uid);

    /**
     * 名称模糊匹配当前部门下人
     *
     * @param name
     * @param orgId
     * @return
     */
    List<MbOrgEmployeeInfo> listByNameAndOrgId(String name, String orgId);

    /**
     * 添加员工岗位
     *
     * @return
     */
    boolean addEmployeesPosition(List<SubmitSelectEmpVo> empVos, Long postId);

    /**
     * 是不是后台用户
     *
     * @param uid
     * @return
     */
    boolean isBackgroundUser(String uid);

    /**
     * 批量获取员工
     *
     * @param ids 员工ids
     * @return
     */
    List<MbOrgEmployeeInfo> listByUids(List<String> ids);

    /**
     * 清除员工岗位信息
     *
     * @return
     */
    boolean clearEmployeesPosition(List<SubmitSelectEmpVo> submitSelectEmpVos);

	List<MbOrgEmployeeInfo> selectByUid(String uid);

	List<MbOrgEmployeeInfo> listByUidsAllPlat(List<String> ids);

    /**
     * 姓名模糊匹配query，查找指定orgids下的人
     *
     * @param query
     * @param orgIds
     * @return
     */
    List<MbOrgEmployeeInfo> listByNameAndOrgIds(String query, List<String> orgIds, Integer status, Integer pageNum, Integer pageSize);
    IPage<MbOrgEmployeeInfo> pageByNameAndOrgIds(String query, List<String> orgIds, Integer status, Integer pageNum, Integer pageSize);

//    /**
//     * 根据手机号查询
//     *
//     * @param employeePhone
//     * @param departmentList
//     * @param page
//     * @param pageSize
//     * @return
//     */
//    List<MbOrgEmployeeInfo> listByEmployeePhoneAndOrgIdsPage(String employeePhone, List<String> departmentList, Integer page, Integer pageSize);

    /**
     * 批量查询后台员工
     *
     * @param uids
     * @return
     */
    List<MbOrgEmployeeInfo> listBackUserByUids(List<String> uids);

    /**
     * 用户名和手机号模糊匹配key
     *
     * @param key      匹配内容
     * @param page     页数
     * @param pageSize 每页显示大小
     * @param orgValid 组织有效性
     * @return 用户集合
     */
    List<MbOrgEmployeeInfo> fuzzyByNameAndTel(String key, Integer page, Integer pageSize, Boolean orgValid);

    /**
     * 保存用户
     * {@link #create(MbOrgEmployeeInfo)}
     * @param mbOrgEmployeeInfo
     * @return
     */
	@Deprecated
    boolean save(MbOrgEmployeeInfo mbOrgEmployeeInfo);

	/**
	 * 通过手机号查询用户是否存在
	 *
	 * @param phoneNum 手机号
	 * @return
	 */
	MbOrgEmployeeInfo findByMobilePhone(String areaCode, String phoneNum);
    List<OrgPostLogVo> queryAdminLog(List<String> uids, String orgId);

    List<MbOrgEmployeeInfo> listUnAuditEmployee(String uid, Integer pageNum, Integer pageSize);

    List<EmployeeInfoResponseBo> listEmployeeInfo(List<OrgUserInfoPk> pkList);

//    /**
//     * 模糊匹配uid和name在组织结构列表中来查询用户
//     *
//     * @param key    关键字
//     * @param orgIds
//     * @return 员工列表
//     */
//    List<MbOrgEmployeeInfo> fuzzyUserByUidAndNameInOrgs(String key, List<String> orgIds);

    /**
     * 修改员工信息
     *
     * @param employee
     * @return
     */
    Integer updateEmployeeSelective(MbOrgEmployeeInfo employee);

    /**
     * 新增员工
     *
     * @param employee
     * @return
     */
    ServiceErrorEnum addEmployee(MbOrgEmployeeInfo employee, List<MbOrgUserIdcard> cardTypes, List<MbOrgUserFfpinfo> ffps, List<MbUserOrgRelation> orgRelations);

    /**
     * 修改员工
     *
     * @param employee
     * @param cardTypes
     * @param ffps
     * @param orgRelations
     * @return
     */
    ServiceErrorEnum updateEmployee(MbOrgEmployeeInfo employee, List<MbOrgUserIdcard> cardTypes, List<MbOrgUserFfpinfo> ffps, List<MbUserOrgRelation> orgRelations);

	/**
	 * 删除员工
	 *
	 * @param employee
	 * @return
	 */
    ServiceErrorEnum deleteEmployee(MbOrgEmployeeInfo employee);

	/**
	 * 根据职级id查询
	 *
	 * @param postIds
	 * @return
	 */
	List<MbOrgEmployeeInfo> listByPostIds(List<Long> postIds);

	List<MbOrgEmployeeInfo> listByRoleIds(List<Long> roleIds);

	/**
	 * 根据名称模糊查询后台用户
	 *
	 * @param name
	 * @return
	 */
	List<MbOrgEmployeeInfo> findBgUserByName(String name);

	/**
	 * 根据名称模糊查询用户
	 *
	 * @param name
	 * @return
	 */
	List<MbOrgEmployeeInfo> findLikeName(String name);

	List<MbOrgEmployeeInfo> findLikeName(List<String> orgIds, String name);

	/**
	 * 根据名称精确查询用户
	 *
	 * @param name
	 * @return
	 */
	List<MbOrgEmployeeInfo> findByName(String name);

	/**
	 * 查询
	 * @param request
	 * @return
	 */
	OrgEmployeeVo searchEmployeeInfo(SearchEmployeeInfoRequestBO request);

	List<OrgEmployeeVo> findOrgInfoByUid(String uid);

	List<SearchCorpEmpResponse> selectEmployeeByOrgIds(List<String> orgIds);

	List<EmployeeOrgVo> findEmployeeInfoByIds(List<String> ids);

	QueryEmployeeResponse queryEmployeeList(QueryEmployeeRequest request);

	SearchCorpEmpResponse findEmpAndOrgByUid(String uid);

	/**
	 * 更新用户信息
	 *
	 * @param request
	 * @return
	 */
	UpdateEmployeeResponseBO updateByUid(UpdateEmployeeRequestBO request);


	/**
	 * 	根据Orgid经过数据权限配置的组织数据获取员工
	 * @param orgId
	 * @return
	 */
	List<UserEmailDTO> findUserInfoByOrgIds(List<String> orgId);

    List<MbOrgEmployeeInfo> findUidByOrgId(List<String> orgId);

    /**
     * 批量获取这些uids对应的前台员工，并且满足其他任意条件
     *
     * @param uidList 员工uid，未传则返回空列表
     * @param phone 员工电话号码，精确匹配，未传则不筛选
     * @param email 员工邮箱，精确匹配，未传则不筛选
     * @param pageIndex 页码
     * @param pageSize 一页数量
     */
    IPage<MbOrgEmployeeInfo> pageByUidsAndAnyParam(List<String> uidList, String phone, String email, Integer pageIndex,
        Integer pageSize);

	UpdateEmployeeResponseBO updateEmployeeTypeByUid(Integer employeeType, List<String>	ids);

    List<MbOrgEmployeeInfo> findManageFuzzy(FindManageFuzzyRequestBO request);

	List<MbOrgEmployeeInfo> findAllBackgroundUsers();


	QueryEmployeeInfoWithPermissionResponse queryEmployeeWithPermission(QueryEmployeeInfoWithPermissionRequest request);

	List<EmployeeInfoVo> getEmployeeInfoByUidList(List<EmployeeByUidRequestVo> request);

	Boolean refreshEmployeeBirthAndGender(String request);
    /**
     * 搜索员工信息
     * @param request
     * @return
     */
    ListEmployeeByConditionResponse listEmployeeByCondition(ListEmployeeByConditionRequest request);
}
